package com.osce.web.controller.system;

import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.entity.entity.SubjectManage;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.system.service.ISubjectManageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 科目管理Controller
 *
 * @author hdj
 * @since 2025-11-10
 */
@RestController
@RequestMapping("/system/manage")
public class SubjectManageController extends BaseController {

    @Resource
    private ISubjectManageService subjectManageService;

/**
 * 查询科目管理列表
 */
@PreAuthorize("@ss.hasPermi('system:manage:list')")
@GetMapping("/list")
    public TableDataInfo list(SubjectManage subjectManage) {
        startPage();
        List<SubjectManage> list = subjectManageService.selectSubjectManageList(subjectManage);
        return getDataTable(list);
    }

    /**
     * 导出科目管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:export')")
    @Log(title = "科目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SubjectManage subjectManage) {
        List<SubjectManage> list = subjectManageService.selectSubjectManageList(subjectManage);
        ExcelUtil<SubjectManage> util = new ExcelUtil<SubjectManage>(SubjectManage. class);
        util.exportExcel(response, list, "科目管理数据");
    }

    /**
     * 获取科目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:manage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(subjectManageService.selectSubjectManageById(id));
    }

    /**
     * 新增科目管理
     */
    @PreAuthorize("@ss.hasPermi('system:manage:add')")
    @Log(title = "科目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SubjectManage subjectManage) {
        return toAjax(subjectManageService.insertSubjectManage(subjectManage));
    }

    /**
     * 修改科目管理
     */
    @PreAuthorize("@ss.hasPermi('system:manage:edit')")
    @Log(title = "科目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubjectManage subjectManage) {
        return toAjax(subjectManageService.updateSubjectManage(subjectManage));
    }

    /**
     * 删除科目管理
     */
    @PreAuthorize("@ss.hasPermi('system:manage:remove')")
    @Log(title = "科目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(subjectManageService.deleteSubjectManageByIds(ids));
    }
}
